<?php
/**
 * 栏目管理 model(数据层)
 *
 * @package         YDCMS
 * @author          QQ:644157559 <644157559@qq.com>
 * @version         $Id: ContypeModel.class.php v1.0 2014-06-13 17:27:03 $
 */
namespace Admin\Model;
class ContypeModel extends CommonModel{
    // realtions
    protected $_link = array(
        'Model' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name' => 'Model',
            //'mapping_fields' => 'name',
            'foreign_key' => 'model_id',
            'as_fields' => 'name:model_name,addtable',
        )
    );
    //自动验证
    protected $_validate = array(     
        array('typename', 'require', '栏目名称不能为空！', 1, 'regex', self::MODEL_BOTH), //栏目验证
        array('model_id', 'checkModel', '模型选择有误！', 1, 'callback', self::MODEL_BOTH), //模型验证
        array('ispart', array(0, 1, 2), '栏目属性错误！', 1, 'in', self::MODEL_BOTH), //栏目属性验证
        array('lang', "checkLang", '语言选择有误！', 2, 'callback'), 
    );
    
    /**
     * 检查模型
     * @param type $model_id
     * @return boolean
     */
    public function checkModel($model_id) {
        return D("Model", "Service")->existModel($model_id);
    }
    
    /**
     * 检查语言是否存在
     * @param type $lang
     * @return type
     */
    public function checkLang($lang) {
        return D("Language", "Service")->existLang($lang);
    }
}
